package DMSXL._2023Before.String_;

public class lengthOfLastWord {
    public static void main(String[] args) {
        String s = "a";
        System.out.println(new lengthOfLastWord().lengthOfLastWord(s));
    }
    public int lengthOfLastWord(String s) {

        char[] ch = s.toCharArray();
        int index = ch.length - 1;
        while(ch[index] == ' '){
            index --;
        }
        int count = 0;
        if(index == 0)
            return 1;
        while(ch[index] != ' '){
            if(index == 0){
                count++;
                break;
            }
            count++;
            index -- ;
        }
        return count;
    }
}
